package com.gxuwz.action;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.google.gson.Gson;
import com.gxuwz.core.model.Cols;
import com.gxuwz.core.model.Page;
import com.gxuwz.core.util.UidUtils;
import com.gxuwz.core.web.action.BaseAction;
import com.gxuwz.pojo.Form;
import com.gxuwz.service.IFormService;
import com.opensymphony.xwork2.ModelDriven;

public class FormAction extends BaseAction implements ModelDriven<Form>{


	protected static final String LIST_JSP = "/WEB-INF/page/form/form_list.jsp";  
	protected static final String ADD_JSP = "/WEB-INF/page/form/form_add.jsp"; 
	protected static final String TEMPLATE_FORM_JSP = "/WEB-INF/page/form/form_template_form.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/form/form_edit.jsp"; 
	protected static final String TOPIC_ADD_JSP = "/WEB-INF/page/form/form_topic_add.jsp"; 
	protected static final String WRITER_ADD_JSP = "/WEB-INF/page/form/form_writer_add.jsp"; 

	@Autowired
	private IFormService formService;
	
	private Page pageUtil;
	private Form form = new Form();
	
	

	public String asTemplate(){ 
		form = formService.findById(form.getId());
		form.setFormName(form.getFormName()+"（模板）");
		setForwardView(TEMPLATE_FORM_JSP);
		return SUCCESS;
	}

	
	public String toList(){
		setForwardView(LIST_JSP);
		return SUCCESS;
	}
	public String toAdd(){
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	public String toTopicAdd(){
		setForwardView(TOPIC_ADD_JSP);
		return SUCCESS;
	}
	public String toWriterAdd(){
		form = formService.findById(form.getId());
		setForwardView(WRITER_ADD_JSP);
		return SUCCESS;
	}
	
	/**
	 * 弹出修改页面
	 * @return
	 */
	public String toEdit(){
		form = formService.findById(form.getId());
		setForwardView(EDIT_JSP);
		return SUCCESS;
	}
	
	
	public void list(){
		pageUtil = formService.getPage(form, getPage(), getLimit());
		reJson(pageUtil);
		return;
	}
	
	public String save(){
		form.setFormId(UidUtils.UID());
		formService.save(form);
		setForwardView(TOPIC_ADD_JSP);
		return SUCCESS;
	}
	
	public void del(){
		formService.remove(form);
	}
	
	public void update(){
		formService.update(form);
	}

	public Form getForm() {
		return form;
	}

	public void setForm(Form form) {
		this.form = form;
	}

	@Override
	public Form getModel() {
		// TODO Auto-generated method stub
		return form;
	}
	

	
	
	
}
